package cn.basic.social.demo.controller;

import cn.basic.social.demo.vo.JsonResult;
import cn.basic.social.manager.config.SocialConfigProperties;
import cn.basic.social.manager.config.SocialRequestFactory;
import cn.basic.social.manager.handler.login.LoginRequest;
import cn.basic.social.manager.handler.login.LoginResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SocialLoginController
 * @Description TODO
 * @Author zlf
 * @Date 2023/9/28 15:23
 */
@Slf4j
@RestController
@RequestMapping("/login")
public class SocialLoginController {

    @Autowired
    private SocialRequestFactory socialRequestFactory;

    /**
     * 根据用户扫码获取到的code和state进行换取用户的基本信息
     *
     * @param
     * @return
     * @author zlf
     * @date 17:22 2023/9/8
     */
    @GetMapping(value = "getuserinfo")
    public JsonResult<LoginResponse> getuserinfo() throws Exception {

        // 模拟数据
        LoginRequest loginRequest = new LoginRequest();
        loginRequest.setCode("111111111");
        loginRequest.setState("214321312");

        LoginResponse loginResponse = socialRequestFactory.doLoginExecute(SocialConfigProperties.TypeEnum.QiWei_ThirdPart.name(), loginRequest);
        return JsonResult.success(loginResponse);
    }

}
